package com.macro.mall.controller;


import com.baidu.aip.ocr.AipOcr;
import com.macro.mall.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@Api(tags = "orcController", description = "orc文字识别")
@RequestMapping("/orc")
public class BaiduOrcController {

    @Autowired
    private AipOcr client ;


    @ApiOperation("orc文字识别")
    @RequestMapping(value = "/toWorld", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Map<String,Object>> toWorld(@RequestParam(value = "imageurl") String url) {

        HashMap<String, String> options = new HashMap<String, String>();
        options.put("language_type", "CHN_ENG");
        options.put("detect_direction", "true");
        options.put("detect_language", "true");
        options.put("probability", "true");

        // 通用文字识别, 图片参数为远程url图片
        JSONObject res = client.basicGeneralUrl(url, options);
        System.out.println(res.toString(2));
        return CommonResult.success(res.toMap());
    }


}
